from rest_framework import serializers
from .models import Nav, Banner, Category


class NavModelSerializer(serializers.ModelSerializer):
    """
    导航菜单的序列化器
    """
    class Meta:
        model = Nav
        fields = ["name", "link", "is_http"]

class BannerModelSerializer(serializers.ModelSerializer):
    """
    轮播广告的序列化器
    """
    class Meta:
        model = Banner
        fields = ["image", "name", "link", "is_http"]

class ChildCategorySerializer(serializers.ModelSerializer):
    class Meta:
        model=Category
        fields = ['cname','id']
class CategorySerializer(serializers.ModelSerializer):
    children=ChildCategorySerializer(many=True)
    class Meta:
        model = Category
        fields ='__all__'

